package dviz.visualSystem;

import java.util.HashMap;
import dviz.visualAspect.MetaPropertyMap;
import dviz.visualSystem.impl.PropertyQueryable;

/**
 * @author zxq071000
 */
public class DummyAnimationSystem implements AnimationSystem {

	HashMap<Object, HashMap<String, MetaPropertyMap>> objects = new HashMap<Object, HashMap<String, MetaPropertyMap>>();
	/**
	 * @uml.property  name="propertyQueryable"
	 * @uml.associationEnd  
	 */
	public PropertyQueryable propertyQueryable;

	{
		(new Thread() {
			@Override
			public void run() {
				while (true) {
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					fireQuery();
				}
			}
		}).start();
	}

	@Override
	public void createObject(Object key, String clazz,
			HashMap<String, Object> argument,
			HashMap<String, MetaPropertyMap> propertyQueriable,
			boolean attachToRoot) {
		System.out.println("DumyAnimationSystem->CreateObject()" + key);
		objects.put(key, propertyQueriable);
	}

	@Override
	public void invokeAction(Object key, String actionName,
			HashMap<String, Object> param) {
		System.out.println("DumyAnimationSystem->InvokeAction()" + actionName);
	}

	@Override
	public void removeObject(Object key) {
		System.out.println("DumyAnimationSystem->RemoveObject()" + key);
	}

	public void fireQuery() {
		for (Object k : objects.keySet()) {
			for (MetaPropertyMap o : objects.get(k).values()) {
				try {
					System.out.println("DumyAnimationSystem->FireQuery  " + o
							+ "=" + propertyQueryable.queryProperty(k, o));
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}
}
